<?php
/**
 * Yii view form
 *
 * @author <KTD SOFT>
 * @since Jan 11, 2013 - 2:46:02 PM
 */
?>
<div class="row-fluid">
    <div class="grid-content">
        <?php
        $this->beginWidget('MyActiveForm_menu', array(
            'model'       => $this->model,
            'title'       => $this->pageTitle,
            'htmlOptions' => array('class' => 'span hide'),
            'columns'     => array(
                array(
                    'field'       => 'name',
                    'htmlOptions' => array('class'    => "",
                        'readonly' => "readonly",),
                ),
            ),
        ));
        ?>
        <div class="clear"></div>
        <div class="row-fluid">
            <div class="grid span4">
                <div class="grid-title">
                    <div class="pull-left"><?php echo $this->model->name ?></div>
                    <div class="pull-right">
                        <a class="btn btn-primary" href="<?php
                        echo $this->createUrl('menu/update', array(
                            'lang' => $this->lang,
                            'pk'   => $this->model->id
                        ))
                        ?>">
                            <i class="icon icon-plus" style="padding-right:4px;"></i>Thêm menu
                        </a>
                    </div>
                    <div class="clear"></div>
                </div>
                <div class="grid-content">
                    <?php
                    echo $this->renderPartial('_treemenu', array(
                        'model' => $this->model
                    ))
                    ?>
                </div>
            </div>
            <div class="grid span8">
                <div class="grid-title">
                    <div class="pull-left"><?php echo 'Form Menu' ?></div>
                    <div class="clear"></div>
                </div>
                <div class="grid-content">
                    <?php
                    echo $this->renderPartial('_formupdate', array(
                    ))
                    ?>
                </div>
            </div>
        </div>
    </div>
</div>
<?php $this->endWidget() ?>
<script>
    function remove_item(el, id)
    {
        el.parent().remove();
        hidden_input = '<input type="hidden" value="' + id + '" name="deleteItem[]"  />';
        $('#createLink').before(hidden_input);
    }
    function add_item()
    {
        id = jQuery.now();
        form = '<div class="formRow">';
        form += '<input type="text" name="MenuItem[' + id + '][name]" placeholder="<?php echo Yii::t('menuitem', 'Name') ?>" />';
        form += '<input type="text" name="MenuItem[' + id + '][description]" placeholder="<?php echo Yii::t('menuitem', 'Description') ?>" />';
        form += '<select name="MenuItem[' + id + '][type]">';
<?php foreach (MenuItem::getArrayType() as $type => $type_name): ?>
            form += '<option value="<?php echo $type ?>" >';
            form += '<?php echo $type_name ?>';
            form += '</option>'
<?php endforeach; ?>
        form += '</select>';
        form += '<input type="text" name="MenuItem[' + id + '][value]" placeholder="<?php echo Yii::t('menuitem', 'Value') ?>"';
        form += 'value=""/>';
        form += '<input type="text" name="MenuItem[' + id + '][rank]" placeholder="<?php echo Yii::t('menuitem', 'Rank') ?>"';
        form += 'value=""/>';
        form += '<a class="btn btn-mini btn-inverse" href="#" onclick="$(this).parent().remove()">';
        form += '<?php echo Yii::t('form', 'Delete') ?>';
        form += '</a>';
        form += '<div class="clear"></div>';
        form += '</div>';

        $('#createLink').before(form);
        return false;
    }
    function add_Childitem()
    {
        id = jQuery.now();
        form = '<div class="pull-right">';
        form += '<input type="text" name="MenuItem[' + id + '][name]" placeholder="<?php echo Yii::t('menuitem', 'Name') ?>" />';
        //                form += '<input type="text" name="MenuItem[' + id + '][description]" placeholder="<?php echo Yii::t('menuitem', 'Description') ?>" />';
        form += '<select name="MenuItem[' + id + '][type]">';
<?php foreach (MenuItem::getArrayType() as $type => $type_name): ?>
            form += '<option value="<?php echo $type ?>" >';
            form += '<?php echo $type_name ?>';
            form += '</option>';
<?php endforeach; ?>
        form += '</select>';
        form += '<input type="text" name="MenuItem[' + id + '][value]" placeholder="<?php echo Yii::t('menuitem', 'Value') ?>"';
        form += 'value=""/>';
        form += '<input type="text" name="MenuItem[' + id + '][rank]" placeholder="<?php echo Yii::t('menuitem', 'Rank') ?>"';
        form += 'value=""/>';
        form += '</select>';

        form += '<select name="MenuItem[' + id + '][parent_id]" placeholder="<?php echo Yii::t('menuitem', 'Parent ID') ?>">';
        form += '<?php foreach ($this->model->items as $item): ?>';
            form += '<option value="<?php echo $item->id ?>">';
            form += '<?php echo $item->name ?>';
            form += '</option>';
            form += '<?php endforeach; ?>';
        form += '</select>';
        form += '<a class="btn btn-mini btn-inverse" href="#" onclick="$(this).parent().remove()">';
        form += '<?php echo Yii::t('form', 'Delete') ?>';
        form += '</a>';
        form += '<div class="clear"></div>';
        form += '</div>';

        $('#createLink').before(form);
        return false;
    }
</script>